<div class="container-fluid" style="margin-top: 10px;">
    <div class="row">

        <div class="col-sm-12">
            <label>变动设备</label>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>设备编号</th>
                    <th>设备名称</th>
                    <th>隶属单位</th>
                    <th>使用部门</th>
                    <th>价值</th>
                    <th>当前状态</th>
                    <th>入账时间</th>
                </tr>
                </thead>
                <tbody>
                {volist name='list' id='vo'}
                <tr>
                    <td>{$vo.FACILITY_NO}</td>
                    <td>{$vo.FACILITY}</td>
                    <td>{$vo.BELONG}</td>
                    <td>{$vo.USE_DEPART_NAME}</td>
                    <td>{$vo.PRICE}</td>
                    <td>{$vo.STATE}</td>
                    <td>{$vo.ENTERTIME}</td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>

        <div class="col-sm-12">
            <label>变动表单</label>
            <div class="col-sm-12" style="border: 1px solid #ddd;padding: 10px 0px">
                <form id="alterForm" method="post" action="addAlter">
                    <input hidden name="ids" value="{$ids}">
                    {:form('select2',['title'=>'变动类型','name'=>'ALTERTYPE_ID','url'=>'dict/getSbAlterType','key'=>'ALTERTYPE_ID','field'=>'ALTERTYPE'])}
                    {:form('select2',['title'=>'变动原因','name'=>'ALTERCAUSE_ID','url'=>'dict/getSbAlterCause','key'=>'ALTERCAUSE_ID','field'=>'ALTERCAUSE'])}
                    {:form('date',['title'=>'变动时间','name'=>'ALTER_DATE'])}
                    <div id="altertype02" style="display: none;">
                        {:form('text',['title'=>'变动价值','name'=>'PRICE_AFT','pl'=>'增值输入正数，减值输入负数'])}
                    </div>
                    <div id="altertype05" style="display: none;">
                        {:form('depart',['c_title'=>'变动至学院','b_name'=>'DEPARTID_AFT'])}
                    </div>
                    <div id="altertype99" style="display: none;">
                        {:form('text',['title'=>'报废处理方式','name'=>'DISPOSE'])}
                        {:form('text',['title'=>'处理单据号','name'=>'DISPOSE_RECNO'])}
                        {:form('text',['title'=>'处理价格','name'=>'DISPOSE_PRICE'])}
                    </div>
                    {:form('text',['title'=>'备注','name'=>'COMMENTS'])}
                    {:form('select2',['title'=>'是否审核','name'=>'IS_AUDIT','url'=>'dict/getAudit','key'=>'ID','field'=>'NAME'])}
                    {:line()}
                    {:form('text',['title'=>'制单人','disable'=>'disabled','value'=>$Think.session.user_name])}
                    {:form('text',['title'=>'制单时间','disable'=>'disabled','value'=>date('Y-m-d')])}
                </form>
            </div>
        </div>

        <div class="col-sm-12" style="margin-top: 10px;text-align: center">
            <button id="submit" class="btn btn-info">确认变更</button>
        </div>
    </div>
</div>

<script>

    $(function () {

        $("[name='ALTERTYPE_ID']").on('change',function () {
            var type = $("[name='ALTERTYPE_ID']").val();
            console.log(type);
            if(type == '02'){
                $("#altertype02").show();
                $("#altertype05").hide();
                $("#altertype99").hide();
            }
            else if(type == '05'){
                $("#altertype02").hide();
                $("#altertype05").show();
                $("#altertype99").hide();
            }
            else if(type == '99'){
                $("#altertype02").hide();
                $("#altertype05").hide();
                $("#altertype99").show();
            }
        });

        $("#submit").on('click',function () {
            layer.confirm('确认执行变更吗？',function (index) {
                layer.close(index);
                layer.load();
                $("#alterForm").ajaxSubmit(function (text) {
                    console.log(text);
                    layer.closeAll('loading');
                    var json = JSON.parse(text);
                    if(json['code']=='200'){
                        layer.alert(json['msg'],{icon:1},function (index) {
                            layer.close(index);
                            parent.location.reload();
                        });
                    }
                    else{
                        layer.alert(json['msg'],{icon:2});
                    }
                });
            });
        });
    });


</script>